﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

using MaxStudio.Concrete.DBUtility;

namespace MaxStudio.Concrete.Server.Dao
{
    public partial class ConcreteDaoDataContext : System.Data.Linq.DataContext
    {
        #region RPTSchoolConcreteTestDao

        public List<tb_RPT_SchoolConcreteTest> GetAllSchoolConcreteTest()
        {
            var query = (from obj in this.tb_RPT_SchoolConcreteTests
                         where obj.IsDelete == 0
                         select obj).ToList();
            return query;
        }


        public List<tb_RPT_SchoolConcreteTest> GetSchoolConcreteTestByContition(string strProjectName, string strStrengtGrade)
        {
            var tq = from obj in this.tb_RPT_SchoolConcreteTests
                     where obj.IsDelete == 0
                     select obj;

            if (strProjectName.Length > 0)
            {
                tq = tq.Where(entity => entity.ProjectName == strProjectName);
            }

            if (strStrengtGrade.Length > 0)
            {
                tq = tq.Where(entity => entity.StrengtGrade == strStrengtGrade);
            }
            
           
            var query = tq.ToList();
            return query;
        }

        public tb_RPT_SchoolConcreteTest GetSchoolConcreteTestById(int id)
        {
            return this.tb_RPT_SchoolConcreteTests.SingleOrDefault(tb_RPT_SchoolConcreteTests => tb_RPT_SchoolConcreteTests.Id == id);
        }

        public void CreateSchoolConcreteTest(tb_RPT_SchoolConcreteTest entity)
        {
            entity.CreateDate = DateTime.Now;
            entity.CreateBy = 1;
            entity.ModifyDate = DateTime.Now;
            entity.ModifyBy = 1;
            tb_RPT_SchoolConcreteTests.InsertOnSubmit(entity);
            this.SubmitChanges();

        }

        public void ModifySchoolConcreteTest(tb_RPT_SchoolConcreteTest entity)
        {
            tb_RPT_SchoolConcreteTest instance = this.tb_RPT_SchoolConcreteTests.SingleOrDefault(p => p.Id == entity.Id);
            instance.ProjectName = entity.ProjectName;
            instance.StrengtGrade = entity.StrengtGrade;
            instance.InputDate3Day = entity.InputDate3Day;
            instance.ClearedPeople3Day = entity.ClearedPeople3Day;
            instance.InputDate7Day = entity.InputDate7Day;
            instance.ClearedPeople7Day = entity.ClearedPeople7Day;  

            instance.IsDelete = entity.IsDelete;
            instance.ModifyBy = 1; //Need to get current user
            instance.ModifyDate = DateTime.Now;

            this.SubmitChanges();
        }

        public void DeleteSchoolConcreteTest(tb_RPT_SchoolConcreteTest entity)
        {
            tb_RPT_SchoolConcreteTest deleteEntity = tb_RPT_SchoolConcreteTests.SingleOrDefault(p => p.Id == entity.Id);
            tb_RPT_SchoolConcreteTests.DeleteOnSubmit(deleteEntity);

            this.SubmitChanges();
        }

        #endregion

    }
}
